﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using web.ui.Service_RouteDetail;
using System.Web.Script.Serialization;
using NHibernate.Criterion;
using bus.console.service.bus.vo;
using bus.console.service.bus;

public partial class Service_RouteDetail : BasePage
{
    private readonly char splitChar = ';';
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            doAction();
        }
    }

    private void doAction()
    {
        string rtid = Request.QueryString["rtid"];//必填=pathAttributeId (PK)
        string city = Request.QueryString["city"];//必填
        string gob = Request.QueryString["gob"];//必填
        string info = Request.QueryString["info"];

        int JoyConfig_Count = 0;
        DetachedCriteria dCriteriadCriteriaJoyConfig = DetachedCriteria.For(typeof(JoyConfig));
        dCriteriadCriteriaJoyConfig.Add(Expression.Eq("JoyID", "StopMarkerShowNumber"));
        IList<JoyConfig> JoyConfigList = myService.ExecutableDetachedCriteria<JoyConfig>(dCriteriadCriteriaJoyConfig, 0, 1);
        if (JoyConfigList != null && JoyConfigList.Count != 0)
        {
            JoyConfig joyConfig = JoyConfigList[0];
            JoyConfig_Count = int.Parse(joyConfig.JoyValue);
        }
        else
        {
            throw new Exception("JoyConfig.JoyID的值無StopMarkerShowNumber");
        }


        if (JoyConfig_Count != 0)
        {
            if (!string.IsNullOrEmpty(rtid) && !string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(gob))
            {
                if (string.IsNullOrEmpty(info))
                {
                    //路線上所有站牌附近地標類型與資訊
                    ResultShow1VO show1VO = new ResultShow1VO();
                    RouteShowVO routeShow1VO = new RouteShowVO();
                    IList<StopShowVO> stopShowList = new List<StopShowVO>();
                    Dictionary<int, string> diList = new Dictionary<int, string>();
                    string routeId = GetRoute(rtid);
                    if (!string.IsNullOrEmpty(routeId))
                    {
                        Route route = myService.Dao.DaoGetVOById<Route>(routeId);

                        #region type="stop"
                        if (route != null)
                        {
                            IList<Stop> stopList = busService.GetRouteAllStop(rtid, city, gob);

                            if (stopList != null && stopList.Count > 0)
                            {
                                foreach (Stop stop in stopList)
                                {
                               // Stop stop = stopList[0];
                                    StopShowVO stopShowVO = new StopShowVO();
                                    IList<MarkerShowVO> markerShowList = new List<MarkerShowVO>();
                                    IList<MarkerClassShowVO> markerclassShowList = new List<MarkerClassShowVO>();

                                    stopShowVO.id = stop.Id;
                                    //其他欄位
                                    stopShowVO.city = stop.City;
                                    stopShowVO.goback = stop.Goback;


                                    #region Get :marker_class (地標類型)
                                    IList<StopMarkerClass_Cache> stopMarkerClassCacheList =busService.GetStopMarkerClass(stop.Id, city);
                                    if (stopMarkerClassCacheList != null && stopMarkerClassCacheList.Count > 0)
                                    {
                                        foreach (StopMarkerClass_Cache stopMarkerClassCache in stopMarkerClassCacheList)
                                        {
                                            DetachedCriteria dCriteriaMarkerClass = DetachedCriteria.For(typeof(MarkerClass));
                                            dCriteriaMarkerClass.Add(Expression.Eq("ID", stopMarkerClassCache.MarkerClassID));
                                            IList<MarkerClass> markerClassList = myService.Dao.ExecutableDetachedCriteria<MarkerClass>(dCriteriaMarkerClass);

                                            if (markerClassList != null && markerClassList.Count > 0)
                                            {
                                                foreach (MarkerClass markerClass in markerClassList)
                                                {
                                                    MarkerClassShowVO markerClassShowVO = new MarkerClassShowVO();
                                                    markerClassShowVO.id = markerClass.ID;
                                                    markerClassShowVO.name = markerClass.NameZh;
                                                    //add marker_class detail
                                                    markerclassShowList.Add(markerClassShowVO);
                                                }
                                            }

                                        }
                                    }
                                    #endregion

                                    #region Get:marker (地標資訊)

                                    
                                    #region 取出shop
                                    IList<StopMarker_Cache> stopMarkerCacheList = busService.GetStopMarker(stop.Id, city, JoyConfig_Count);

                                    if (stopMarkerCacheList != null && stopMarkerCacheList.Count != 0)
                                    {
                                        foreach (StopMarker_Cache stopMarkerCache in stopMarkerCacheList)
                                        {
                                            //MarkerInfo markerInfo = myService.DaoGetVOById<MarkerInfo>(stopMarkerCache.MarkerID.ID);
                                            MarkerInfo markerInfo = stopMarkerCache.MarkerID;
                                            if (markerInfo != null)
                                            {
                                                MarkerShowVO markerShowVO = new MarkerShowVO();
                                                markerShowVO.id = markerInfo.ID.ToString().Trim();
                                                markerShowVO.name = markerInfo.NameZh.ToString().Trim();
                                                markerShowVO.class_id = markerInfo.MarkerClassID;
                                                markerShowVO.dist = stopMarkerCache.dist;

                                                //更新StopMarker_Cache (ShowCount+1)
                                                stopMarkerCache.ShowCount += 1;
                                                myService.DaoUpdate(stopMarkerCache);

                                                // add marker detail
                                                markerShowList.Add(markerShowVO);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region 取出不是shop
                                    if (markerShowList.Count < JoyConfig_Count)
                                    {
                                        int count = JoyConfig_Count - markerShowList.Count;
                                        IList<StopMarker_Cache> stopMarkerCacheList_noShop = busService.GetStopMarker_noShop(stop.Id, city, count);
                                        foreach (StopMarker_Cache stopMarkerCache in stopMarkerCacheList_noShop)
                                        {
                                            if (markerShowList.Count < JoyConfig_Count)
                                            {
                                                if (stopMarkerCacheList_noShop != null && stopMarkerCacheList_noShop.Count != 0)
                                                {

                                                    //MarkerInfo markerInfo = myService.DaoGetVOById<MarkerInfo>(stopMarkerCache.MarkerID.ID);
                                                    MarkerInfo markerInfo = stopMarkerCache.MarkerID;

                                                    if (markerInfo != null)
                                                    {
                                                        if (markerInfo.ShowPriority > stopMarkerCache.ShowCount)
                                                        {
                                                            MarkerShowVO markerShowVO = new MarkerShowVO();
                                                            markerShowVO.id = markerInfo.ID;
                                                            markerShowVO.name = markerInfo.NameZh.ToString().Trim();
                                                            markerShowVO.class_id = markerInfo.MarkerClassID.ToString().Trim();
                                                            markerShowVO.dist = stopMarkerCache.dist;

                                                            // add marker detail
                                                            markerShowList.Add(markerShowVO);

                                                            //更新StopMarker_Cache (ShowCount+1)
                                                            stopMarkerCache.ShowCount += 1;
                                                            myService.DaoUpdate(stopMarkerCache);
                                                            diList.Add(stopMarkerCache.ID, stopMarkerCache.StopID);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                    if (markerShowList.Count < JoyConfig_Count)
                                    {
                                        //取出筆數不足JoyConfig.JoyValue,把StopMarker_Cache.ShowCount重置為0
                                        int count = JoyConfig_Count - markerShowList.Count;
                                        IList<StopMarker_Cache> stopMarkerCacheList2 = busService.GetStopMarker2(stop.Id, city, diList, count);
                                        if (stopMarkerCacheList2!=null && stopMarkerCacheList2.Count != 0)
                                        {
                                            foreach (StopMarker_Cache StopMarker_CacheLsit in stopMarkerCacheList2)
                                            {
                                                StopMarker_CacheLsit.ShowCount = 0;
                                                myService.DaoUpdate(StopMarker_CacheLsit);
                                            }
                                        }

                                        //把剛重置為StopMarker_Cache.ShowCount=0抓出來加入
                                       // IList<StopMarker_Cache> stopMarkerCacheList_Count = busService.GetStopMarker2(stop.Id, city, diList, count);

                                        if (stopMarkerCacheList2 != null && stopMarkerCacheList2.Count != 0)
                                        {
                                            foreach (StopMarker_Cache stopMarkerCache2 in stopMarkerCacheList2)
                                            {
                                                if (markerShowList.Count < JoyConfig_Count)
                                                {
                                                    //取出不是shop
                                                    //MarkerInfo markerInfo2 = myService.DaoGetVOById<MarkerInfo>(stopMarkerCache2.MarkerID.ID);
                                                    MarkerInfo markerInfo2 =stopMarkerCache2.MarkerID;
                                                    if (markerInfo2 != null)
                                                    {
                                                        MarkerShowVO markerShowVO = new MarkerShowVO();
                                                        markerShowVO.id = markerInfo2.ID.ToString().Trim();
                                                        markerShowVO.name = markerInfo2.NameZh.ToString().Trim();
                                                        markerShowVO.class_id = markerInfo2.MarkerClassID;
                                                        markerShowVO.dist = stopMarkerCache2.dist;

                                                        // add marker detail
                                                        markerShowList.Add(markerShowVO);
                                                        stopMarkerCache2.ShowCount += 1;
                                                        myService.DaoUpdate(stopMarkerCache2);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion Get:marker
                                    //add marker_class;marker
                                    stopShowVO.marker_class = markerclassShowList;
                                    stopShowVO.marker = markerShowList;
                                    //add stop detail
                                    stopShowList.Add(stopShowVO);
                                }
                            }

                            //add stop
                            show1VO.stop = stopShowList;
                            
                        }

                        #endregion type="stop"
                    }

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    String json = serializer.Serialize(show1VO);
                    Response.Write(json);
                    Response.End();
                }
                else
                {
                    ResultShow2VO show2VO = new ResultShow2VO();
                    RouteShow2VO routeShow2VO = new RouteShow2VO();
                    IList<StopShow2VO> stopShow2List = new List<StopShow2VO>();
                    Dictionary<int, string> diList = new Dictionary<int, string>();
                    //依據不同info取出資料結果

                    string routeId2 = GetRoute(rtid);

                    if (!string.IsNullOrEmpty(routeId2))
                    {
                        Route route = myService.Dao.DaoGetVOById<Route>(routeId2);

                        if (route != null)
                        {
                            List<String> infoStrList = new List<string>();
                            infoStrList = info.Split(splitChar).ToList<String>();
                            if (infoStrList != null && infoStrList.Count > 0)
                            {
                                #region info含(stop) or (marker) or (marker.photo) or (marker_class)
                                if (infoStrList.Contains<String>("stop") || infoStrList.Contains<String>("marker") || infoStrList.Contains<String>("marker.photo") || infoStrList.Contains<String>("marker_class"))
                                {
                                    //此路線的所有站牌的地標
                                    IList<Stop> stopList =busService.GetRouteAllStop(rtid, city, gob);
                                    if (stopList != null && stopList.Count > 0)
                                    {
                                        foreach (Stop stop in stopList)
                                        {
                                            StopShow2VO stopShow2VO = new StopShow2VO();
                                            IList<MarkerShow2VO> markerShow2List = new List<MarkerShow2VO>();
                                            IList<MarkerClassShow2VO> markerclassShow2List = new List<MarkerClassShow2VO>();

                                            stopShow2VO.id = stop.Id;
                                            stopShow2VO.city = stop.City;

                                            #region Get:marker (地標資訊)
                                            if (infoStrList.Contains<String>("marker") || infoStrList.Contains<String>("marker.photo"))
                                            {
                                                #region 取出shop
                                                IList<StopMarker_Cache> stopMarkerCacheList = busService.GetStopMarker(stop.Id, city, JoyConfig_Count);

                                                if (stopMarkerCacheList != null && stopMarkerCacheList.Count > 0)
                                                {
                                                    foreach (StopMarker_Cache stopMarkerCache in stopMarkerCacheList)
                                                    {
                                                        if (markerShow2List.Count < JoyConfig_Count)
                                                        {
                                                            MarkerInfo markerInfo = stopMarkerCache.MarkerID;
                                                            if (markerInfo != null)
                                                            {

                                                                MarkerShow2VO markerShow2VO = new MarkerShow2VO();
                                                                markerShow2VO.id = markerInfo.ID.ToString().Trim();
                                                                markerShow2VO.name = markerInfo.NameZh.ToString().Trim();
                                                                markerShow2VO.class_id = markerInfo.MarkerClassID.ToString().Trim();
                                                                markerShow2VO.dist = stopMarkerCache.dist;

                                                                #region photo
                                                                if (infoStrList.Contains<String>("marker.photo"))
                                                                {
                                                                    IList<PhotoShow2VO> photoShow2List = new List<PhotoShow2VO>();
                                                                    DetachedCriteria dCriteriaPhoto = DetachedCriteria.For(typeof(MarkerPhoto));
                                                                    dCriteriaPhoto.Add(Expression.Eq("MarkerID", markerInfo.ID));
                                                                    IList<MarkerPhoto> markerPhotoList = myService.Dao.ExecutableDetachedCriteria<MarkerPhoto>(dCriteriaPhoto);
                                                                    if (markerPhotoList != null && markerPhotoList.Count > 0)
                                                                    {
                                                                        foreach (MarkerPhoto markerPhoto in markerPhotoList)
                                                                        {
                                                                            PhotoShow2VO photoShow2VO = new PhotoShow2VO();
                                                                            photoShow2VO.url = markerPhoto.URL;
                                                                            photoShow2VO.sort = markerPhoto.Sort;

                                                                            //add photo detail
                                                                            photoShow2List.Add(photoShow2VO);
                                                                        }

                                                                        //add photo
                                                                        markerShow2VO.photo = photoShow2List;
                                                                    }
                                                                }
                                                                #endregion photo

                                                                // add marker detail
                                                                markerShow2List.Add(markerShow2VO);
                                                                stopMarkerCache.ShowCount += 1;
                                                                myService.DaoUpdate(stopMarkerCache);
                                                            }
                                                        }
                                                    }
                                                }
                                                #endregion

                                                #region 取出不是shop
                                                if (markerShow2List.Count < JoyConfig_Count)
                                                {
                                                    int count = JoyConfig_Count - markerShow2List.Count;
                                                    IList<StopMarker_Cache> stopMarkerCacheList_NoShop = busService.GetStopMarker_noShop(stop.Id, city, count);

                                                    if (stopMarkerCacheList_NoShop != null && stopMarkerCacheList_NoShop.Count > 0)
                                                    {
                                                        foreach (StopMarker_Cache stopMarkerCache in stopMarkerCacheList_NoShop)
                                                        {
                                                            if (markerShow2List.Count < JoyConfig_Count)
                                                            {
                                                                MarkerInfo markerInfo = stopMarkerCache.MarkerID;
                                                                if (markerInfo != null)
                                                                {
                                                                    if (markerInfo.ShowPriority > stopMarkerCache.ShowCount)
                                                                    {
                                                                        MarkerShow2VO markerShow2VO = new MarkerShow2VO();
                                                                        markerShow2VO.id = markerInfo.ID.ToString().Trim();
                                                                        markerShow2VO.name = markerInfo.NameZh.ToString().Trim();
                                                                        markerShow2VO.class_id = markerInfo.MarkerClassID.ToString().Trim();
                                                                        markerShow2VO.dist = stopMarkerCache.dist;

                                                                        #region photo
                                                                        if (infoStrList.Contains<String>("marker.photo"))
                                                                        {
                                                                            IList<PhotoShow2VO> photoShow2List = new List<PhotoShow2VO>();

                                                                            DetachedCriteria dCriteriaPhoto = DetachedCriteria.For(typeof(MarkerPhoto));
                                                                            dCriteriaPhoto.Add(Expression.Eq("MarkerID", markerInfo.ID));
                                                                            IList<MarkerPhoto> markerPhotoList = myService.Dao.ExecutableDetachedCriteria<MarkerPhoto>(dCriteriaPhoto);
                                                                            if (markerPhotoList != null && markerPhotoList.Count > 0)
                                                                            {
                                                                                foreach (MarkerPhoto markerPhoto in markerPhotoList)
                                                                                {
                                                                                    PhotoShow2VO photoShow2VO = new PhotoShow2VO();
                                                                                    photoShow2VO.url = markerPhoto.URL;
                                                                                    photoShow2VO.sort = markerPhoto.Sort;

                                                                                    //add photo detail
                                                                                    photoShow2List.Add(photoShow2VO);
                                                                                }

                                                                                //add photo
                                                                                markerShow2VO.photo = photoShow2List;
                                                                            }
                                                                        }
                                                                        #endregion photo

                                                                        // add marker detail
                                                                        markerShow2List.Add(markerShow2VO);
                                                                        stopMarkerCache.ShowCount += 1;
                                                                        myService.DaoUpdate(stopMarkerCache);

                                                                        diList.Add(stopMarkerCache.ID, stopMarkerCache.StopID);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                #endregion

                                                if (markerShow2List.Count < JoyConfig_Count)
                                                {
                                                    int count = JoyConfig_Count - markerShow2List.Count;
                                                    //取出筆數不足JoyConfig.JoyValue,把StopMarker_Cache.ShowCount重置為0
                                                    IList<StopMarker_Cache> stopMarkerCacheList2 = busService.GetStopMarker2(stop.Id, city, diList, count);
                                                    if (stopMarkerCacheList2.Count != 0)
                                                    {
                                                        foreach (StopMarker_Cache StopMarker_CacheLsit in stopMarkerCacheList2)
                                                        {
                                                            StopMarker_CacheLsit.ShowCount = 0;
                                                            myService.DaoUpdate(StopMarker_CacheLsit);
                                                        }
                                                    }

                                                    //把剛重置為StopMarker_Cache.ShowCount=0抓出來加入
                                                    //IList<StopMarker_Cache> stopMarkerCacheList_Count = busService.GetStopMarker2(stop.Id, city, diList, count);

                                                    if (stopMarkerCacheList2 != null && stopMarkerCacheList2.Count != 0)
                                                    {
                                                        foreach (StopMarker_Cache stopMarkerCache2 in stopMarkerCacheList2)
                                                        {
                                                            //取出不是shop
                                                            if (markerShow2List.Count < JoyConfig_Count)
                                                            {
                                                                MarkerInfo markerInfo2 = stopMarkerCache2.MarkerID;
                                                                if (markerInfo2 != null)
                                                                {
                                                                    if (markerShow2List.Count < JoyConfig_Count)
                                                                    {
                                                                        MarkerShow2VO markerShow2VO = new MarkerShow2VO();
                                                                        markerShow2VO.id = markerInfo2.ID.ToString().Trim();
                                                                        markerShow2VO.name = markerInfo2.NameZh.ToString().Trim();
                                                                        markerShow2VO.class_id = markerInfo2.MarkerClassID.ToString().Trim();
                                                                        markerShow2VO.dist = stopMarkerCache2.dist;

                                                                        #region photo
                                                                        if (infoStrList.Contains<String>("marker.photo"))
                                                                        {
                                                                            IList<PhotoShow2VO> photoShow2List = new List<PhotoShow2VO>();

                                                                            DetachedCriteria dCriteriaPhoto = DetachedCriteria.For(typeof(MarkerPhoto));
                                                                            dCriteriaPhoto.Add(Expression.Eq("MarkerID", markerInfo2.ID));
                                                                            IList<MarkerPhoto> markerPhotoList = myService.Dao.ExecutableDetachedCriteria<MarkerPhoto>(dCriteriaPhoto);
                                                                            if (markerPhotoList != null && markerPhotoList.Count > 0)
                                                                            {
                                                                                foreach (MarkerPhoto markerPhoto in markerPhotoList)
                                                                                {
                                                                                    PhotoShow2VO photoShow2VO = new PhotoShow2VO();
                                                                                    photoShow2VO.url = markerPhoto.URL;
                                                                                    photoShow2VO.sort = markerPhoto.Sort;

                                                                                    //add photo detail
                                                                                    photoShow2List.Add(photoShow2VO);
                                                                                }

                                                                                //add photo
                                                                                markerShow2VO.photo = photoShow2List;
                                                                            }
                                                                        }
                                                                        #endregion photo

                                                                        // add marker detail
                                                                        markerShow2List.Add(markerShow2VO);
                                                                        stopMarkerCache2.ShowCount += 1;
                                                                        myService.DaoUpdate(stopMarkerCache2);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                // add marker 
                                                stopShow2VO.marker = markerShow2List;
                                                #endregion Get:marker

                                                #region Get :marker_class
                                                if (infoStrList.Contains<String>("marker_class"))
                                                {
                                                    IList<StopMarkerClass_Cache> stopMarkerClassCacheList =busService.GetStopMarkerClass(stop.Id, city);
                                                    if (stopMarkerClassCacheList != null && stopMarkerClassCacheList.Count > 0)
                                                    {
                                                        foreach (StopMarkerClass_Cache stopMarkerClassCache in stopMarkerClassCacheList)
                                                        {
                                                            DetachedCriteria dCriteriaMarkerClass = DetachedCriteria.For(typeof(MarkerClass));
                                                            dCriteriaMarkerClass.Add(Expression.Eq("ID", stopMarkerClassCache.MarkerClassID));
                                                            IList<MarkerClass> markerClassList = myService.Dao.ExecutableDetachedCriteria<MarkerClass>(dCriteriaMarkerClass);

                                                            if (markerClassList != null && markerClassList.Count > 0)
                                                            {
                                                                foreach (MarkerClass markerClass in markerClassList)
                                                                {
                                                                    MarkerClassShow2VO markerClassShow2VO = new MarkerClassShow2VO();
                                                                    markerClassShow2VO.id = markerClass.ID.ToString().Trim();
                                                                    markerClassShow2VO.name = markerClass.NameZh.ToString().Trim();
                                                                    //add marker_class detail
                                                                    markerclassShow2List.Add(markerClassShow2VO);
                                                                }
                                                            }

                                                        }

                                                        // add marker_class 
                                                        stopShow2VO.marker_class = markerclassShow2List;
                                                    }
                                                }
                                                #endregion

                                                //add stop detail
                                                stopShow2List.Add(stopShow2VO);
                                            }
                                        }

                                        //add stop
                                        show2VO.stop = stopShow2List;
                                    }
                                #endregion
                                }
                            }
                        }

                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        String json = serializer.Serialize(show2VO);
                        Response.Write(json);
                        Response.End();
                    }
                }
            }
            else
            {
                emptyResult();
            }
        }
        else
        {
            throw new NotImplementedException("JoyValue=0");
        }

    }
        

    private string GetRoute(string rtid)
    {
        DetachedCriteria dCriteria = DetachedCriteria.For(typeof(Route));
        dCriteria.Add(Expression.Eq("pathAttributeID", rtid));
        IList<Route> routeList = myService.Dao.ExecutableDetachedCriteria<Route>(dCriteria, 0, 1);
        if (routeList != null && routeList.Count > 0)
        {
            return routeList[0].ID;
        }
        else
        {
            return "";
        }
    }

    /// <summary>
    /// 站牌的地標類型
    /// </summary>
    /// <param name="stopId"></param>
    /// <param name="city"></param>
    /// <returns></returns>
    //private IList<StopMarkerClass_Cache> GetStopMarkerClass(string stopId, string city)
    //{
    //    DetachedCriteria dCriteriaMarkerClass_C = DetachedCriteria.For(typeof(StopMarkerClass_Cache));
    //    dCriteriaMarkerClass_C.Add(Expression.Eq("City", city));
    //    dCriteriaMarkerClass_C.Add(Expression.Eq("StopID", stopId));
    //    IList<StopMarkerClass_Cache> stopMarkerClassCacheList = myService.Dao.ExecutableDetachedCriteria<StopMarkerClass_Cache>(dCriteriaMarkerClass_C);
    //    return stopMarkerClassCacheList;
    //}

    /// <summary>
    /// 站牌的地標資訊_Shop
    /// </summary>
    /// <param name="stopId"></param>
    /// <param name="city"></param>
    /// <returns></returns>
    //private IList<StopMarker_Cache> GetStopMarker(string stopId, string city, int JoyConfig_Count)
    //{
    //    DetachedCriteria dCriteriaStopMarker_C = DetachedCriteria.For(typeof(StopMarker_Cache));
    //    dCriteriaStopMarker_C.Add(Expression.Eq("StopID", stopId));
    //    dCriteriaStopMarker_C.Add(Expression.Eq("City", city));
    //    dCriteriaStopMarker_C.CreateCriteria("MarkerID").Add(Expression.Eq("DataSource","shop"));
    //    IList<StopMarker_Cache> stopMarkerCacheList = myService.Dao.ExecutableDetachedCriteria<StopMarker_Cache>(dCriteriaStopMarker_C, 0, JoyConfig_Count);
    //    return stopMarkerCacheList;
    //}

    /// <summary>
    /// 站牌的地標資訊_NoShop
    /// </summary>
    /// <param name="stopId"></param>
    /// <param name="city"></param>
    /// <returns></returns>
    //private IList<StopMarker_Cache> GetStopMarker_noShop(string stopId, string city, int JoyConfig_Count)
    //{
    //    DetachedCriteria dCriteriaStopMarker_C = DetachedCriteria.For(typeof(StopMarker_Cache));
    //    dCriteriaStopMarker_C.Add(Expression.Eq("StopID", stopId));
    //    dCriteriaStopMarker_C.Add(Expression.Eq("City", city));
    //    dCriteriaStopMarker_C.CreateCriteria("MarkerID").Add(Expression.Not(Expression.Eq("DataSource","shop")));
    //    IList<StopMarker_Cache> stopMarkerCacheList = myService.Dao.ExecutableDetachedCriteria<StopMarker_Cache>(dCriteriaStopMarker_C, 0, JoyConfig_Count);
    //    return stopMarkerCacheList;
    //}

    /// <summary>
    /// 站牌的地標資訊
    /// </summary>
    /// <param name="stopId"></param>
    /// <param name="city"></param>
    /// <returns></returns>
    //private IList<StopMarker_Cache> GetStopMarker2(string stopId, string city, Dictionary<int, string> diList, int JoyConfig_Count)
    //{
    //    DetachedCriteria dCriteriaStopMarker_C = DetachedCriteria.For(typeof(StopMarker_Cache));
    //    dCriteriaStopMarker_C.Add(Expression.Eq("StopID", stopId));
    //    dCriteriaStopMarker_C.Add(Expression.Eq("City", city));
    //    dCriteriaStopMarker_C.CreateCriteria("MarkerID").Add(Expression.Not(Expression.Eq("DataSource", "shop")));
    //    dCriteriaStopMarker_C.Add(Expression.Not(Expression.In("ID", diList.Keys)));
    //    IList<StopMarker_Cache> stopMarkerCacheList = myService.Dao.ExecutableDetachedCriteria<StopMarker_Cache>(dCriteriaStopMarker_C, 0, JoyConfig_Count);
    //    return stopMarkerCacheList;
    //}

    /// <summary>
    /// 同路線所有站牌
    /// </summary>
    /// <param name="rtid"></param>
    /// <param name="city"></param>
    /// <param name="gob"></param>
    /// <returns></returns>
    //private IList<Stop> GetRouteAllStop(string rtid, string city, string gob)
    //{
    //    IList<Stop> stopList = new List<Stop>();
    //    DetachedCriteria dCriteria = DetachedCriteria.For(typeof(PathDetail));
    //    dCriteria.Add(Expression.Eq("pathAttributeId", rtid));
    //    IList<PathDetail> PathDetailList = myService.Dao.ExecutableDetachedCriteria<PathDetail>(dCriteria);
    //    if (PathDetailList != null && PathDetailList.Count > 0)
    //    {
    //        foreach (PathDetail pathDetail in PathDetailList)
    //        {
    //            DetachedCriteria dCriteriaStop = DetachedCriteria.For(typeof(Stop));
    //            dCriteriaStop.Add(Expression.Eq("Id", pathDetail.stopId));//站牌
    //            dCriteriaStop.Add(Expression.Eq("City", city));
    //            dCriteriaStop.Add(Expression.Eq("Goback", gob));

    //            IList<Stop> stopRawList = myService.Dao.ExecutableDetachedCriteria<Stop>(dCriteriaStop);
    //            if (stopRawList != null && stopRawList.Count > 0)
    //            {
    //                foreach (Stop stop in stopRawList)
    //                {
    //                    stopList.Add(stop);
    //                }
    //            }
    //        }
    //    } 

    //    return stopList;
    //}

    private void emptyResult()
    {
        ResultShow1VO show1VO = new ResultShow1VO();
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        String json = serializer.Serialize(show1VO);
        Response.Write(json);
        Response.End();
       
    }

}


namespace web.ui.Service_RouteDetail
{
    class ResultShow1VO
    {
        public virtual IList<StopShowVO> stop { get; set; }

    }

    #region ResultShow1--沒有info
    class RouteShowVO
    {
        public virtual String id { get; set; }
        public virtual String name { get; set; }
        public virtual String from { get; set; }
        public virtual String to { get; set; }
    }

    class StopShowVO
    {
        public virtual String id { get; set; }

        public virtual String city { get; set; }

        public virtual String goback { get; set; }

        public virtual IList<MarkerClassShowVO> marker_class { get; set; }

        public virtual IList<MarkerShowVO> marker { get; set; }
    }

    class MarkerClassShowVO
    {
        public virtual String id { get; set; }

        public virtual String name { get; set; } 

    }

    class MarkerShowVO
    {
        public virtual String id { get; set; }

        public virtual String name { get; set; }

        public virtual String class_id { get; set; }

        public virtual float dist { get; set; } 
    }
    #endregion

    class ResultShow2VO
    {
        public virtual IList<StopShow2VO> stop { get; set; }

    }

    #region ResultShow2--有info

    class RouteShow2VO
    {
        public virtual String id { get; set; }
        public virtual String name { get; set; }
        //public virtual String com_name { get; set; }
        public virtual String from { get; set; }
        public virtual String to { get; set; }
        public virtual String distance { get; set; }
        public virtual String go_first_time { get; set; }
        public virtual String go_last_time { get; set; }
        public virtual String back_first_time { get; set; }
        public virtual String back_last_time { get; set; }
        public virtual String peak { get; set; }
        public virtual String off_peak { get; set; }
        public virtual String city { get; set; }

    }

    class StopShow2VO
    {
        public virtual String id { get; set; }
        public virtual String city { get; set; }

        public virtual IList<MarkerClassShow2VO> marker_class { get; set; }
        public virtual IList<MarkerShow2VO> marker { get; set; }
    }


    class MarkerClassShow2VO
    {
        public virtual String id { get; set; }
        public virtual String name { get; set; } 
    }
    class MarkerShow2VO
    {
        public virtual String id { get; set; }
        public virtual String name { get; set; }
        public virtual String class_id { get; set; }
        public virtual float dist { get; set; } 
        public  IList<PhotoShow2VO> photo;
    }

    class PhotoShow2VO
    {
        public virtual String url { get; set; }
        public virtual String sort { get; set; } 
    }
    #endregion

}
